package com.zuipin.controller;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.zuipin.framework.annotation.Valid;
import com.zuipin.framework.annotation.Valids;
import com.zuipin.framework.emuns.ErrorCode;
import com.zuipin.framework.exception.CustomException;
import com.zuipin.framework.result.Result;
import com.zuipin.service.IThirdAccountService;
import com.zuipin.util.RegexUtils;
import com.zuipin.vo.MemberInfoVo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

/** 
 * @ClassName: RedPackServiceImpl 
 * @author wuyicheng
 * @time 2017年3月27日下午4:04:09 
 */
@Api(value = "", description = "-wuyicheng")
@RestController
@RequestMapping(value = "/thirdAccount")
public class ThirdAccountController {
	
	@Resource
	private IThirdAccountService thirdAccountService;
	
	@RequestMapping(value = "/searchIsCanBinding", method = RequestMethod.GET)
	@ApiOperation(value = "查询是否可以绑定手机-wuyicheng", notes = "查询是否可以绑定手机-wuyicheng" + "</br>返回码" + "</br>0-成功" + "</br>1001-参数异常" + "</br>1004-系统异常" + "</br>3006-会员不存在"
			+ "</br>3007-会员账号不存在" + "</br>3008-手机好已经绑定另一个账号" + "</br>3009-第三方账号不存在" + "</br>4031-两个账号分别绑定不同手机号，无法修改" + "</br>4032-该手机号已经存在一个相同平台的第三方账号")
	@Valids({ @Valid(name = "phone", regex = RegexUtils.MOBILE_FUZZY), @Valid(name = "isThirderAccount", regex = "true|false") })
	@ApiImplicitParams({ @ApiImplicitParam(name = "memberId", value = "当前登录用户ID", required = true, dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "sysId", value = "系统ID", required = true, dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "phone", value = "绑定手机名", required = true, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "isThirderAccount", value = "当前是否是第三方帐号(true|false) 选true，平台类型ID是必填的", required = true, dataType = "boolean", paramType = "query"),
			@ApiImplicitParam(name = "platformId", value = "平台类型ID:360安全用户=46,腾讯QQ用户=47,支付宝用户=48,微信用户=49,迅雷用户=50", required = false, dataType = "long", paramType = "query"), })
	public Result<Map<String, Object>> searchIsCanBinding(@RequestParam Long memberId, @RequestParam String phone, @RequestParam Long sysId, @RequestParam boolean isThirderAccount,
			@RequestParam(required = false) Long platformId) throws CustomException {
		Result<Map<String, Object>> result = new Result<>();
		Result<MemberInfoVo> tempResult = thirdAccountService.toUpdatePhone(memberId, sysId, phone, isThirderAccount, platformId, false);
		result.setErrorCode(tempResult.getErrorCode());
		result.setCode(tempResult.getCode());
		result.setMessage(tempResult.getMessage());
		return result;
	}
	
	@ApiIgnore
	@RequestMapping(value = "/bindingMobileByThirdAccount", method = RequestMethod.GET)
	@ApiOperation(value = "查询会员账户信息-wuyicheng", notes = "查询会员账户信息-wuyicheng" + "</br>返回码" + "</br>0-成功" + "</br>1004-系统异常" + "</br>4031-两个账号分别绑定不同手机号，无法修改"
			+ "</br>4032-该手机号已经存在一个相同平台的第三方账号")
	@Valids({ @Valid(name = "mobilePhone", regex = RegexUtils.MOBILE_FUZZY), //
			@Valid(name = "openId", required = true), //
			@Valid(name = "sysId", required = true), //
			@Valid(name = "platformId", required = true), })
	@ApiImplicitParams({ @ApiImplicitParam(name = "mobilePhone", value = "绑定手机号", required = true, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "openId", value = "第三方账号", required = true, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "sysId", value = "系统ID", required = true, dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "platformId", value = "第三方平台ID", required = true, dataType = "long", paramType = "query"), })
	public Result<Map<String, Object>> bindingMobileByThirdAccount(String mobilePhone, String openId, Long sysId, Long platformId) {
		Result<Map<String, Object>> result = new Result<>();
		// openId + sysId + platformId 查询是否绑定手机
		
		// mobilePhone + sysId 绑定的手机号是否绑定第三方
		
		// 根据手机号和平台Id，系统Id查询是否存同一个平台的第三方账号
		
		// ThirdAccount thirdAccount = new ThirdAccount();
		result.setErrorCode(ErrorCode.SUCCESS);
		return result;
	}
	
}
